﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using BLL;
using IFactory;
using System.IO;

public partial class UserPlanMonth_NoEvaluateUserPlanMonth : System.Web.UI.Page
{
    QuarterDateManager dllQuarterDateManager = new QuarterDateManager();
    MonthDateManager dllMonthDateManager = new MonthDateManager();
    IBussinessLogic dllUserInfo = new UserInfoManager();
    UserPlanMonth dllUserPlanMonth = new UserPlanMonth();
    Authentication dllAuthentication = new Authentication();
    VerifyCircuitManager dllVerifyCircuitManager = new VerifyCircuitManager();
    Model.UserInfo objUserInfo = new Model.UserInfo();
    DataTable _powerTable = new DataTable();
    protected void Page_Load(object sender, EventArgs e)
    {

        if (!IsPostBack)
        {
            if (Request.Params["type"] != null && Request.Params["type"].ToString().Length != 0)
            {
                this.drpType.SelectedIndex = this.drpType.Items.IndexOf(this.drpType.Items.FindByValue(Request.Params["type"].ToString()));
            }

            if (this.drpType.SelectedValue == "1")
            {
                this.btnOk.Visible = true;
                this.btnReturn.Visible = true;
            }
            else
            {
                this.btnOk.Visible = false;
                this.btnReturn.Visible = false;
            }
            bindDropDownList(this.drpYear);
            bindDropDownList(this.drpQuarterDate);
            if (this.drpType.SelectedItem.Value == "0")
            {
                //绑定待评估
                bindGridViewCheckNote();
                this.ckbAllSelect.Visible = false;
                this.btnReturn.Visible = false;

            }
            else
            {
                //绑定是否达成共识
                bindGridView();
                this.ckbAllSelect.Visible = true;
                this.btnReturn.Visible = true;
            }

        }
    }


    /// <summary>
    /// 绑定所有的dropdownlist
    /// </summary>
    /// <param name="_drp"></param>
    void bindDropDownList(DropDownList _drp)
    {
        //年份绑定
        if (_drp.Equals(this.drpYear))
        {
            for (int i = 2009; i < 2100; i++)
            {
                ListItem _li = new ListItem(i.ToString(), i.ToString());
                _drp.Items.Add(_li);
            }
            //根据系统日期自动绑定到当前年份
            string _year = DateTime.Now.Year.ToString();
            this.drpYear.SelectedIndex = this.drpYear.Items.IndexOf(this.drpYear.Items.FindByText(_year));

        }

        //绑定年计划周期
        if (_drp.Equals(this.drpQuarterDate))
        {
            object[] _value = new object[1];
            _value[0] = this.drpYear.SelectedValue;
            DataTable _quarter = dllQuarterDateManager.get(QuarterDateManager.field.QuarterYear.ToString(), _value);
            if (_quarter.Rows.Count != 0)
            {
                this.drpQuarterDate.DataSource = _quarter;
                this.drpQuarterDate.DataTextField = "QuarterName";
                this.drpQuarterDate.DataValueField = "Quarter_Id";
                this.drpQuarterDate.DataBind();
                #region dropdownlist显示系统所对应的当前年周期
                if (Request.QueryString["QuarterDate"] == null)
                {
                    //根据系统当前日期查找到对应的年周期
                    DataTable _quartertime = dllQuarterDateManager.getQuarterDate();
                    //如果查到结果（结果只有一条）

                    if (_quartertime.Rows.Count == 1)
                    {
                        this.drpQuarterDate.SelectedIndex = this.drpQuarterDate.Items.IndexOf(this.drpQuarterDate.Items.FindByText(_quartertime.Rows[0][1].ToString()));
                        this.drpQuarterDate.DataSource = _quartertime;
                        this.drpQuarterDate.DataTextField = "QuarterName";
                        this.drpQuarterDate.DataValueField = "Quarter_Id";
                    }
                }
                else
                {
                    this.drpQuarterDate.SelectedValue = Utility.HttpHelp.getParamsString("QuarterDate");
                }
                #endregion
                bindDropDownList(this.drpMonthDate);
            }
            else
            {
                ListItem _li = new ListItem("无年周期");
                this.drpQuarterDate.Items.Clear();
                this.drpQuarterDate.Items.Add(_li);
                bindDropDownList(this.drpMonthDate);
            }


        }

        //绑定月计划周期
        if (_drp.Equals(this.drpMonthDate))
        {

            object[] _value = new object[2];
            _value[0] = this.drpYear.SelectedValue;
            _value[1] = this.drpQuarterDate.SelectedItem.Text;
            DataTable _month = dllMonthDateManager.get(MonthDateManager.field.QuarterName.ToString(), _value);
            if (_month.Rows.Count != 0)
            {
                this.drpMonthDate.DataSource = _month;
                this.drpMonthDate.DataTextField = "MonthName";
                this.drpMonthDate.DataValueField = "Month_Id";
                this.drpMonthDate.DataBind();
                if (Request.QueryString["MonthDate"] == null)
                {
                    #region 根据系统当前日期绑定到当前月周期
                    DataTable _monthtime = dllMonthDateManager.getMonthDate();
                    if (_monthtime.Rows.Count == 1)
                    {
                        this.drpMonthDate.SelectedIndex = this.drpMonthDate.Items.IndexOf(this.drpMonthDate.Items.FindByText(_monthtime.Rows[0][3].ToString()));
                        this.drpMonthDate.DataSource = _monthtime;
                        this.drpMonthDate.DataTextField = "MonthName";
                        this.drpMonthDate.DataValueField = "Month_Id";

                    }
                    if (Request.QueryString["Id"] != null)
                    {
                        this.drpMonthDate.SelectedValue = Utility.HttpHelp.getParamsInt("Id").ToString();
                    }
                    ListItem _li = this.drpType.SelectedItem;
                    if (_li != null)
                    {
                        if (_li.Text == "待审核")
                        {
                            bindGridView();
                        }
                        else
                        {
                            bindGridViewCheckNote();
                        }
                    }
                    #endregion
                    if (Request.QueryString["PreMonthDate"] != null)
                    {
                        object[] _date = new object[1];
                        _date[0] =Convert.ToInt32(this.drpMonthDate.SelectedValue);                        
                        this.drpMonthDate.SelectedValue = dllMonthDateManager.getPreMonthDate(_date).ToString();
                   
                    }
                }
                else
                {
                    this.drpMonthDate.SelectedValue = Utility.HttpHelp.getParamsString("MonthDate");
                }

            }
            else
            {
                ListItem _li = new ListItem("无月周期");
                this.drpMonthDate.Items.Clear();
                this.drpMonthDate.Items.Add(_li);
            }
        }
    }


    /// <summary>
    /// 绑定是否达成共识GridView（处理待评估、待审核计划）
    /// </summary>
    /// <author>grokyao</author>
    /// <date>2009-2-25</date>
    void bindGridView()
    {
        object[] _value = new object[2];
        Model.UserInfo objUserInfo = new Model.UserInfo();
        _value[0] = objUserInfo.UserName;
        ListItem _li = this.drpMonthDate.SelectedItem;
        if (_li != null && _li.Value != "无月周期")
        {
            _value[1] = Convert.ToInt32(_li.Value);
            DataView dv = new DataView(dllUserPlanMonth.getUserPlanMonthNoVerifyAndNoEvaluate(_value));
            dv.Sort = "MonthPlanSortId";
            this.gdvNoVerifyMonthPlan.DataSource = dv;
            this.gdvNoVerifyMonthPlan.DataBind();

            #region 截取字符串
            for (int i = 0; i < this.gdvNoVerifyMonthPlan.Rows.Count; i++)
            {
                if (this.gdvNoVerifyMonthPlan.Rows[i].Cells[10].Text == "&amp;nbsp;" || this.gdvNoVerifyMonthPlan.Rows[i].Cells[10].Text == "&nbsp;")
                {
                    this.gdvNoVerifyMonthPlan.Rows[i].Cells[10].Text = "";
                }

                //文件下载，判断如果下载了就显示《下载按钮》 反之 就显示“无下载”
                if (gdvNoVerifyMonthPlan.DataKeys[i]["AttachmentPath"].ToString().Length == 0)
                {
                    Button _btn = (Button)gdvNoVerifyMonthPlan.Rows[i].Cells[12].FindControl("btnDownLoad");
                    _btn.Visible = false;
                    Label _lbl = (Label)gdvNoVerifyMonthPlan.Rows[i].Cells[12].FindControl("lblAlert");
                    _lbl.Visible = true;
                    _lbl.Text = "无下载";
                }
            }

            #endregion

        }

    }

    /// <summary>
    /// 退回事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnReturn_Click(object sender, EventArgs e)
    {
        //根据评估人查询当前用户的待审月计划
        Model.UserInfo objUserInfo = new Model.UserInfo();

        int _count = 0;
        List<object[]> _valueList = new List<object[]>();
        for (int i = 0; i < this.gdvNoVerifyMonthPlan.Rows.Count; i++)
        {
            string a = this.gdvNoVerifyMonthPlan.Rows[i].Cells[2].Text;
            CheckBox ckb = (CheckBox)this.gdvNoVerifyMonthPlan.Rows[i].Cells[0].FindControl("ckbSelect");
            if (ckb.Checked == true)
            {
                object[] _value = new object[2];
                _value[0] = Convert.ToInt32(this.gdvNoVerifyMonthPlan.DataKeys[i]["MonthPlanId"].ToString());

                TextBox tb = (TextBox)this.gdvNoVerifyMonthPlan.Rows[i].FindControl("txtVerifyPeopleOpinion");
                if (tb.Text.Length < 18)
                {
                    Utility.HttpHelp.alert("审核意见字数不得低于32个字符", Page);
                    return;
                }
                _value[1] = tb.Text;
                _valueList.Add(_value);
                _count++;
            }
        }
        if (_count == 0)
        {
            Utility.HttpHelp.alert("请至少选择一个月计划", Page);
            return;
        }
        BLL.UserPlanMonth dllUserPlanMonth = new UserPlanMonth();
        int result = dllUserPlanMonth.editWithTransaction(MonthPlanManager.field.CheckNote.ToString(), _valueList);
        if (result == 0)
        {
            Utility.Error.RedirectErrorPage("退回月计划评估人评估未成功，请重试！");
        }
        else
        {
            Response.Redirect("NoEvaluateUserPlanMonth.aspx");
        }


    }
    /// <summary>
    /// 通过事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnOk_Click(object sender, EventArgs e)
    {

        //根据评估人查询当前用户的待审月计划
        Model.UserInfo objUserInfo = new Model.UserInfo();

        int _count = 0;
        List<object[]> _valueList = new List<object[]>();
        for (int i = 0; i < this.gdvNoVerifyMonthPlan.Rows.Count; i++)
        {
            string a = this.gdvNoVerifyMonthPlan.Rows[i].Cells[2].Text;
            CheckBox ckb = (CheckBox)this.gdvNoVerifyMonthPlan.Rows[i].Cells[0].FindControl("ckbSelect");
            if (ckb.Checked == true)
            {
                object[] _value = new object[3];
                _value[0] = Convert.ToInt32(this.gdvNoVerifyMonthPlan.DataKeys[i]["MonthPlanId"].ToString());
                _value[1] = objUserInfo.UserName;
                TextBox tb = (TextBox)this.gdvNoVerifyMonthPlan.Rows[i].FindControl("txtVerifyPeopleOpinion");
                if (tb.Text.Length < 18)
                {
                    Utility.HttpHelp.alert("审核意见字数不得低于32个字符", Page);
                    return;
                }
                _value[2] = tb.Text;
                _valueList.Add(_value);
                _count++;
            }
        }
        if (_count == 0)
        {
            Utility.HttpHelp.alert("请至少选择一个月计划", Page);
            return;
        }
        if (this.drpType.SelectedItem.Text != null && this.drpType.SelectedItem.Value == "1")
        {
            //修改发送状态为2，进入审核流程
            int result = dllUserPlanMonth.editWithTransaction(UserPlanMonth.field.EvaluatePeople.ToString(), _valueList);
            //if (result == 0)
            //{
              //  Utility.Error.RedirectErrorPage("提交月计划审核未成功，请重试！");
            //}
            //else
            //{
                Response.Redirect("NoEvaluateUserPlanMonth.aspx");
            //}
        }
    }
    /// <summary>
    /// 全选事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void ckbAllSelect_CheckedChanged(object sender, EventArgs e)
    {
        if (ckbAllSelect.Checked == true)
        {
            for (int i = 0; i < this.gdvNoVerifyMonthPlan.Rows.Count; i++)
            {
                CheckBox ckb = (CheckBox)this.gdvNoVerifyMonthPlan.Rows[i].Cells[0].FindControl("ckbSelect");
                ckb.Checked = true;
            }
        }
        else
        {
            for (int i = 0; i < this.gdvNoVerifyMonthPlan.Rows.Count; i++)
            {
                CheckBox ckb = (CheckBox)this.gdvNoVerifyMonthPlan.Rows[i].Cells[0].FindControl("ckbSelect");
                ckb.Checked = false;
            }
        }
    }
    /// <summary>
    /// 分页事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void gdvNoVerifyMonthPlan_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        this.gdvNoVerifyMonthPlan.PageIndex = e.NewPageIndex;
        bindGridView();
    }



    /// <summary>
    /// 类型改变事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void drpType_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (this.drpType.SelectedItem.Value == "0")
        {
            //绑定待评估
            bindGridViewCheckNote();
            this.gdvNoVerifyMonthPlan.Visible = false;
            this.gdvEvaluteCheckNote.Visible = true;
            this.btnOk.Visible = false;
            this.ckbAllSelect.Visible = false;
            this.btnReturn.Visible = false;
        }
        else
        {
            //绑定是否达成共识
            bindGridView();
            this.gdvNoVerifyMonthPlan.Visible = true;
            this.gdvEvaluteCheckNote.Visible = false;
            this.btnOk.Visible = true;
            this.ckbAllSelect.Visible = true;
            this.btnReturn.Visible = true;
        }
    }

    /// <summary>
    /// 绑定待评估GridView
    /// </summary>
    void bindGridViewCheckNote()
    {
        //根据评估人查询当前用户的待最后一次评估的计划
        Model.UserInfo objUserInfo = new Model.UserInfo();
        object[] _value = new object[2];
        _value[0] = objUserInfo.UserName;
        ListItem _li = this.drpMonthDate.SelectedItem;
        if (_li != null)
        {
            _value[1] = Convert.ToInt32(_li.Value);
            DataView dv = new DataView(dllUserPlanMonth.getUserPlanMonthVerifyedAndEvaluated(_value));
            dv.Sort = "MonthPlanSortId";
            this.gdvEvaluteCheckNote.DataSource = dv;
            this.gdvEvaluteCheckNote.DataBind();
            #region 截取字符串
            for (int i = 0; i < this.gdvEvaluteCheckNote.Rows.Count; i++)
            {

                DropDownList drp = (DropDownList)this.gdvEvaluteCheckNote.Rows[i].Cells[11].FindControl("dropZhuangTai");
                drp.SelectedValue = this.gdvEvaluteCheckNote.DataKeys[i]["PlanSendState"].ToString();
                if (Convert.ToInt32(this.gdvEvaluteCheckNote.DataKeys[i]["PlanSendState"].ToString()) > 3)
                {
                    Button btn = (Button)this.gdvEvaluteCheckNote.Rows[i].Cells[12].FindControl("btnTiJiao");
                    btn.Enabled = false;
                }
                else
                {
                    drp.SelectedValue = "4";
                }
                if (this.gdvEvaluteCheckNote.Rows[i].Cells[10].Text == "&amp;nbsp;" || this.gdvEvaluteCheckNote.Rows[i].Cells[10].Text == "&nbsp;")
                {
                    this.gdvEvaluteCheckNote.Rows[i].Cells[10].Text = "";
                }

            }
            #endregion

            #region
            for (int i = 0; i < gdvEvaluteCheckNote.Rows.Count; i++)
            {
                //文件下载，判断如果下载了就显示《下载按钮》 反之 就显示“无下载”
                if (gdvEvaluteCheckNote.DataKeys[i]["AttachmentPath"].ToString().Length == 0)
                {
                    Button _btn = (Button)gdvEvaluteCheckNote.Rows[i].Cells[12].FindControl("btnDownLoad1");
                    _btn.Visible = false;
                    Label _lbl = (Label)gdvEvaluteCheckNote.Rows[i].Cells[12].FindControl("lblAlert1");
                    _lbl.Visible = true;
                    _lbl.Text = "无下载";
                }
            }

            #endregion
        }



    }


    /// <summary>
    /// 评估意见提交按钮事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnTiJiao_Click(object sender, EventArgs e)
    {
        int i = 0;
        Button bt = (Button)sender;//获得当前控件
        TableCell cell = (TableCell)bt.Parent;//得到所处的父单元格
        GridViewRow iRow = (GridViewRow)cell.Parent;//得到所处父单元行
        i = iRow.RowIndex;//得到该行的索引
        DropDownList drp = (DropDownList)this.gdvEvaluteCheckNote.Rows[i].Cells[11].FindControl("dropZhuangTai");
        ListItem _li = drp.SelectedItem;

        if (_li != null)
        {
            if (_li.Text != "请选择")
            {
                object[] _value = new object[3];
                _value[0] = Convert.ToInt32(this.gdvEvaluteCheckNote.DataKeys[i]["MonthPlanId"].ToString());
                TextBox tb = (TextBox)this.gdvEvaluteCheckNote.Rows[i].Cells[11].FindControl("txtCheckNote");
                tb.Text = tb.Text + "\r\n";
                _value[1] = tb.Text;
                _value[2] = Convert.ToInt32(_li.Value);
                //填写checknote字段内容（追加）
                int result = dllUserPlanMonth.editUserPlanMonthByEvaluatePeople(_value);
                if (result == 0)
                {
                    Utility.Error.RedirectErrorPage("提交评估意见未成功，请重试！");
                }
                else
                {
                    bindGridViewCheckNote();
                }
            }
            else
            {
                Utility.HttpHelp.alert("请选择计划完成状态", Page);
            }
        }
    }


    /// <summary>
    /// 查看流程
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnVerifyCircuit_Click(object sender, EventArgs e)
    {
        int _count = 0;
        string _url = "";
        int _monthId = 0;

        for (int i = 0; i < this.gdvEvaluteCheckNote.Rows.Count; i++)
        {
            CheckBox chk = (CheckBox)this.gdvEvaluteCheckNote.Rows[i].Cells[0].FindControl("ckbSelect");
            if (chk.Checked == true)
            {
                _count++;
                _monthId = Convert.ToInt32(this.gdvEvaluteCheckNote.DataKeys[i]["MonthPlanId"].ToString());

            }
        }

        for (int i = 0; i < this.gdvNoVerifyMonthPlan.Rows.Count; i++)
        {
            CheckBox chk = (CheckBox)this.gdvNoVerifyMonthPlan.Rows[i].Cells[0].FindControl("ckbSelect");
            if (chk.Checked == true)
            {
                _count++;
                _monthId = Convert.ToInt32(this.gdvNoVerifyMonthPlan.DataKeys[i]["MonthPlanId"].ToString());

            }
        }


        if (_count > 1)
        {
            Utility.HttpHelp.alert("只能选择一条月计划", Page);
            return;
        }
        if (_count == 0)
        {
            Utility.HttpHelp.alert("请至少选择一条月计划", Page);
            return;
        }
        if (_count == 1)
        {
            _url = "../WebCommon/VerifyCircruitForUserPlanDisplay.aspx?PlanId=" + _monthId + "&PlanType=4";
            Page.RegisterStartupScript("windowOpen",
               "<script language=javascript>window.open('" + _url + "','newwindow','height=150,width=550,top=250,left=300,toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,status=no');</script>");
        }

    }

    /// <summary>
    /// 年份改变事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void drpYear_SelectedIndexChanged(object sender, EventArgs e)
    {
        bindDropDownList(this.drpQuarterDate);
        bindDropDownList(this.drpMonthDate);
    }


    /// <summary>
    /// 年周期改变事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void drpQuarterDate_SelectedIndexChanged(object sender, EventArgs e)
    {
        bindDropDownList(this.drpMonthDate);
    }


    /// <summary>
    /// 月周期改变
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void drpMonthDate_SelectedIndexChanged(object sender, EventArgs e)
    {
        ListItem _li = this.drpType.SelectedItem;
        if (_li != null)
        {
            if (_li.Text == "待审核")
            {
                bindGridView();
            }
            else
            {
                bindGridViewCheckNote();
            }
        }
    }

    /// <summary>
    /// 下载附件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnDownLoad_Click(object sender, EventArgs e)
    {

        int i = 0;
        Button btt = (Button)sender;//获得当前控件
        TableCell cell = (TableCell)btt.Parent;//得到所处的父单元格
        GridViewRow iRow = (GridViewRow)cell.Parent;//得到所处父单元行
        i = iRow.RowIndex;//得到该行的索引
        //读取隐藏地址列
        string path = this.gdvNoVerifyMonthPlan.DataKeys[i]["AttachmentPath"].ToString();
        FileDownload(path);
        //Utility.HttpHelp.DownloadFile(path);
    }

    ///   <summary>   
    ///   文件下载   
    ///   </summary>   
    ///   <param   name="FullFileName"></param>   
    private void FileDownload(string strFileName)
    {

        FileInfo DownloadFile = new FileInfo(strFileName);
        if (!DownloadFile.Exists)
        {
            Utility.HttpHelp.alert("无附件,请与管理员联系", Page);
            return;
        }
        Response.Clear();
        Response.ClearHeaders();
        Response.Buffer = false;
        Response.ContentType = "application/octet-stream";
        Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(strFileName.Substring(strFileName.LastIndexOf('\\') + 1), System.Text.Encoding.UTF8));
        // Response.AppendHeader("Content-Length", DownloadFile.Length.ToString());

        Response.WriteFile(DownloadFile.FullName);
        Response.Flush();
        Response.End();

    }
    protected void btnDownLoad1_Click(object sender, EventArgs e)
    {

        int i = 0;
        Button btt = (Button)sender;//获得当前控件
        TableCell cell = (TableCell)btt.Parent;//得到所处的父单元格
        GridViewRow iRow = (GridViewRow)cell.Parent;//得到所处父单元行
        i = iRow.RowIndex;//得到该行的索引
        //读取隐藏地址列
        string path = this.gdvEvaluteCheckNote.DataKeys[i]["AttachmentPath"].ToString();
        FileDownload(path);
        //Utility.HttpHelp.DownloadFile(path);
    }


    /// <summary>
    /// 计划来源链接事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void lbtnSource_Click(object sender, EventArgs e)
    {
        int i = 0;
        LinkButton bt = (LinkButton)sender;//获得当前控件
        TableCell cell = (TableCell)bt.Parent;//得到所处的父单元格
        GridViewRow iRow = (GridViewRow)cell.Parent;//得到所处父单元行
        i = iRow.RowIndex;//得到该行的索引
        Control c = (Control)iRow.Parent;
        GridView _gdv = (GridView)c.Parent;

        int MonthPlanId = Convert.ToInt32(_gdv.DataKeys[i]["MonthPlanId"].ToString());
        if (MonthPlanId == 0)
        {
            //新增的员工月计划，不需要跳转到指定页面
        }
        else
        {
            string _url = "MonthPlanDetail.aspx?MonthPlanId=" + MonthPlanId;
            Page.RegisterStartupScript("windowsopen", "<script language=javascript>window.open('" + _url + "','newwindow','height=200,width=900,top=200,left=50,toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,status=no');</script>");
        }
    }


    /// <summary>
    /// 修改事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnMofify_Click(object sender, EventArgs e)
    {
        int _count = 0;
        int _monthId = 0;
        BLL.UserPlanMonth dllUserPlanMonth = new UserPlanMonth();
        for (int i = 0; i < this.gdvNoVerifyMonthPlan.Rows.Count; i++)
        {
            CheckBox ckb = (CheckBox)this.gdvNoVerifyMonthPlan.Rows[i].Cells[0].FindControl("ckbSelect");
            if (ckb.Checked == true)
            {
                _monthId = Convert.ToInt32(this.gdvNoVerifyMonthPlan.DataKeys[i]["MonthPlanId"].ToString());
                _count++;
            }
        }
        //判断上部GridView是否有选中计划
        if (_count == 1)
        {
            //判断是否计划二次评估完成， 评估完成不允许修改。
            object[] _value = new object[1];
            _value[0] = _monthId;
            DataTable monthplan = dllUserPlanMonth.get(UserPlanMonth.field.MonthPlanId.ToString(), _value);
            if (monthplan.Rows.Count == 0)
            {
                if (Convert.ToInt32(monthplan.Rows[0]["PlanSendState"]) >= 4)
                {
                    Utility.HttpHelp.alert("计划已二次评估完成，不允许修改！", Page);
                    return;
                }
            }

            //判断是否评估人
            Model.UserInfo objUser = new Model.UserInfo();
            object[] _user = new object[1];
            _user[0] = objUser.UserName;
            DataTable _userTable = dllUserInfo.get(UserInfoManager.field.UserName.ToString(), _user);

            if (_userTable.Rows.Count > 0)
            {
                object[] _username = new object[2];
                _username[0] = _userTable.Rows[0]["RealName"].ToString();
                _username[1] = _monthId;
                DataTable _iSEvaluatePeople = dllUserPlanMonth.get(UserPlanMonth.field.EvaluatePeople.ToString(), UserPlanMonth.field.MonthPlanId.ToString(), _username);
                if (_iSEvaluatePeople.Rows.Count == 0)
                {
                    Utility.HttpHelp.alert("非评估人不能修改计划", Page);
                }
                else
                {
                    ListItem _li = this.drpMonthDate.SelectedItem;
                    if (_li != null)
                    {
                        string _url = "UserMonthPlanModify.aspx?Id=" + _monthId + "&MonthDate=" + _li.Value + "&url=NoEvaluateUserPlanMonth.aspx&QuarterDate=" + this.drpQuarterDate.SelectedValue + "&Year=" + this.drpYear.SelectedValue + "&Type=1"; ;
                        Page.RegisterStartupScript("windowopen", "<script>window.open('" + _url + "','','height=200,width=1000,top=300,left=20,toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,status=no');</script>");
                        return;
                    }
                }
            }
        }
        else
        {
            //循环下部Gridview判断计划是否选中
            for (int i = 0; i < this.gdvEvaluteCheckNote.Rows.Count; i++)
            {
                CheckBox ckb = (CheckBox)this.gdvEvaluteCheckNote.Rows[i].Cells[0].FindControl("ckbSelect");
                if (ckb.Checked == true)
                {
                    _monthId = Convert.ToInt32(this.gdvEvaluteCheckNote.DataKeys[i]["MonthPlanId"].ToString());
                    _count++;
                }
            }
            if (_count == 1)
            {//判断是否计划二次评估完成， 评估完成不允许修改。
                object[] _value = new object[1];
                _value[0] = _monthId;
                DataTable monthplan = dllUserPlanMonth.get(UserPlanMonth.field.MonthPlanId.ToString(), _value);
                if (monthplan.Rows.Count == 0)
                {
                    if (Convert.ToInt32(monthplan.Rows[0]["PlanSendState"]) >= 4)
                    {
                        Utility.HttpHelp.alert("计划已二次评估完成，不允许修改！", Page);
                        return;
                    }
                }

                //判断是否评估人
                Model.UserInfo objUser = new Model.UserInfo();
                object[] _user = new object[1];
                _user[0] = objUser.UserName;
                DataTable _userTable = dllUserInfo.get(UserInfoManager.field.UserName.ToString(), _user);

                if (_userTable.Rows.Count > 0)
                {
                    object[] _username = new object[2];
                    _username[0] = _userTable.Rows[0]["RealName"].ToString();
                    _username[1] = _monthId;
                    DataTable _iSEvaluatePeople = dllUserPlanMonth.get(UserPlanMonth.field.EvaluatePeople.ToString(), UserPlanMonth.field.MonthPlanId.ToString(), _username);
                    if (_iSEvaluatePeople.Rows.Count == 0)
                    {
                        Utility.HttpHelp.alert("非评估人不能修改计划", Page);
                    }
                    else
                    {
                        ListItem _li = this.drpMonthDate.SelectedItem;
                        if (_li != null)
                        {
                            string _url = "UserMonthPlanModify.aspx?Id=" + _monthId + "&MonthDate=" + _li.Value + "&url=NoEvaluateUserPlanMonth.aspx&QuarterDate=" + this.drpQuarterDate.SelectedValue + "&Year=" + this.drpYear.SelectedValue + "&Type=1";
                            Page.RegisterStartupScript("windowopen", "<script>window.open('" + _url + "','','height=200,width=1000,top=300,left=20,toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,status=no');</script>");
                            return;
                        }
                    }
                }
            }
            if (_count > 1)
            {
                Utility.HttpHelp.alert("只能修改一个计划", Page);
                return;
            }
            if (_count == 0)
            {
                Utility.HttpHelp.alert("请选择一个计划", Page);
                return;
            }
        }
    }
}
